

local gods_paintingSkill = fk.CreateTriggerSkill{
  name = "#lingling__gods_painting_skill",
  attached_equip = "lingling__gods_painting",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted, fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.damageType ~= fk.NormalDamage then
      if event == fk.DamageInflicted then
        return #player.room.logic:getEventsOfScope(GameEvent.Damage, 2, function (e)
          local damage = e.data[1]
          return damage.to == player and damage.damageType ~= fk.NormalDamage
        end, Player.HistoryTurn) == 1
      elseif event == fk.DamageCaused then
        return #player.room.logic:getEventsOfScope(GameEvent.Damage, 2, function (e)
          local damage = e.data[1]
          return damage.from == player and damage.damageType ~= fk.NormalDamage
        end, Player.HistoryTurn) == 1
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    if event == fk.DamageInflicted then
      data.damage = data.damage - 1
    elseif event == fk.DamageCaused then
      data.damage = data.damage + 1
    end
  end,
}
local gods_painting = fk.CreateTreasure{
  name = "&lingling__gods_painting",
  suit = Card.Spade,
  number = 2,
  equip_skill = gods_paintingSkill,
}
Fk:loadTranslationTable{
  ["lingling__gods_painting"] = "八十七神仙卷",
  ["gods_painting"] = "八十七神仙卷",
  ["#lingling__gods_painting_skill"] = "八十七神仙卷",
  [":lingling__gods_painting"] = "装备牌·宝物<br/><b>宝物技能</b>：你每回合首次受到的属性伤害-1，你每回合首次造成的属性伤害+1。",
}

local jialing_riverSkill = fk.CreateTriggerSkill{
  name = "#lingling__jialing_river_skill",
  attached_equip = "lingling__jialing_river",
  frequency = Skill.Compulsory,
  events = {fk.PreCardEffect},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card.trueName == "indulgence" and player.id == data.to
  end,
  on_use = Util.TrueFunc,
}
local jialing_river_maxcards = fk.CreateMaxCardsSkill{
  name = "#lingling__jialing_river_maxcards",
  correct_func = function(self, player)
    if player:hasSkill(jialing_riverSkill) then
      return 3
    end
  end,
}
jialing_riverSkill:addRelatedSkill(jialing_river_maxcards)
Fk:addSkill(jialing_riverSkill)
local jialing_river = fk.CreateTreasure{
  name = "&lingling__jialing_river",
  suit = Card.Spade,
  number = 2,
  equip_skill = jialing_riverSkill,
  on_install = function(self, room, player)
    Treasure.onInstall(self, room, player)
    room:broadcastProperty(player, "MaxCards")
    if player:isAlive() and self.equip_skill:isEffectable(player) and #player:getCardIds("j") > 0 then
      player:throwAllCards("j")
    end
  end,
}
extension:addCard(jialing_river)
Fk:loadTranslationTable{
  ["lingling__jialing_river"] = "嘉陵江三百里",
  ["jialing_river"] = "嘉陵江三百里",
  ["#lingling__jialing_river_skill"] = "嘉陵江三百里",
  [":lingling__jialing_river"] = "装备牌·宝物<br/><b>宝物技能</b>：【乐不思蜀】对你无效。当此牌进入装备区后，你弃置判定区所有牌。你的手牌上限+3。",
}

local buddha_bornSkill = fk.CreateTriggerSkill{
  name = "#lingling__buddha_born_skill",
  attached_equip = "lingling__buddha_born",
}
Fk:addSkill(buddha_bornSkill)
local buddha_born = fk.CreateTreasure{
  name = "&lingling__buddha_born",
  suit = Card.Spade,
  number = 2,
  equip_skill = buddha_bornSkill,
  on_install = function(self, room, player)
    if player:isAlive() and self.equip_skill:isEffectable(player) then
      room:throwCard(self, "#lingling__buddha_born_skill", player, player)
      if not player.dead then
        player:drawCards(1, "#lingling__buddha_born_skill")
      end
      if not player.dead and player:getMark("#lingling__buddha_born_skill") == 0 and math.random() < 0.5 then
        local skills = {}
        for _, general in pairs(Fk.generals) do
          if not general.hidden and not general.total_hidden then
            table.insertTableIfNeed(skills, general:getSkillNameList(true))
          end
        end
        skills = table.filter(skills, function (s)
          return not player:hasSkill(s, true)
        end)
        if #skills > 0 then
          room:setPlayerMark(player, "#lingling__buddha_born_skill", 1)
          room:handleAddLoseSkills(player, table.random(skills), nil, true, false)
        end
      end
    end
  end,
}
extension:addCard(buddha_born)
Fk:loadTranslationTable{
  ["lingling__buddha_born"] = "送子天王图",
  ["buddha_born"] = "送子天王图",
  ["#lingling__buddha_born_skill"] = "送子天王图",
  [":lingling__buddha_born"] = "装备牌·宝物<br/><b>宝物技能</b>：当此牌进入装备区后，你弃置此牌并摸一张牌，然后有50%几率随机获得一个技能"..
  "（每名角色每局限以此法获得一次技能）。",
}

local infernoSkill = fk.CreateTriggerSkill{
  name = "#lingling__inferno_skill",
  attached_equip = "lingling__inferno",
  frequency = Skill.Compulsory,
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(3, self.name)
  end,
}
Fk:addSkill(infernoSkill)
local inferno = fk.CreateTreasure{
  name = "&lingling__inferno",
  suit = Card.Spade,
  number = 2,
  equip_skill = infernoSkill,
}
extension:addCard(inferno)
Fk:loadTranslationTable{
  ["lingling__inferno"] = "地狱变相图",
  ["inferno"] = "地狱变相图",
  ["#lingling__inferno_skill"] = "地狱变相图",
  [":lingling__inferno"] = "装备牌·宝物<br/><b>宝物技能</b>：每回合限一次，当你进入濒死状态后，你摸三张牌。",
}

local vimalakirtiSkill = fk.CreateTriggerSkill{
  name = "#lingling__vimalakirti_skill",
  attached_equip = "lingling__vimalakirti",
  events = {fk.TurnedOver},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not player.faceup and
      player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#lingling__vimalakirti-invoke")
  end,
  on_use = function(self, event, target, player, data)
    player:turnOver()
  end,
}
Fk:addSkill(vimalakirtiSkill)
local vimalakirti = fk.CreateTreasure{
  name = "&lingling__vimalakirti",
  suit = Card.Spade,
  number = 2,
  equip_skill = vimalakirtiSkill,
  on_install = function(self, room, player)
    if player:isAlive() and self.equip_skill:isEffectable(player) and not player.faceup then
      player:turnOver()
    end
  end,
}
extension:addCard(vimalakirti)
Fk:loadTranslationTable{
  ["lingling__vimalakirti"] = "维摩诘经变图",
  ["vimalakirti"] = "维摩诘经变图",
  ["#lingling__vimalakirti_skill"] = "维摩诘经变图",
  [":lingling__vimalakirti"] = "装备牌·宝物<br/><b>宝物技能</b>：每回合限一次，当你翻至背面后，你可以翻至正面。当此牌进入装备区后，"..
  "若你背面朝上，你翻至正面。",
  ["#lingling__vimalakirti-invoke"] = "维摩诘经变图：是否翻回正面？",
}

local door_godSkill = fk.CreateTriggerSkill{
  name = "#lingling__door_god_skill",
  attached_equip = "lingling__door_god",
  frequency = Skill.Compulsory,
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and table.contains({"slash", "duel"}, data.card.trueName) and
      data.from ~= player.id
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local p = room:getPlayerById(data.from)
    if p.dead or p:isNude() or
      #room:askForDiscard(p, 1, 1, true, self.name, false, nil,
        "#lingling__door_god-discard:"..player.id.."::"..data.card:toLogString()) == 0 then
      table.insertIfNeed(data.nullifiedTargets, player.id)
    end
  end,
}
Fk:addSkill(door_godSkill)
local door_god = fk.CreateArmor{
  name = "&lingling__door_god",
  suit = Card.Spade,
  number = 2,
  equip_skill = door_godSkill,
}
extension:addCard(door_god)
Fk:loadTranslationTable{
  ["lingling__door_god"] = "门神",
  ["door_god"] = "门神",
  ["#lingling__door_god_skill"] = "门神",
  [":lingling__door_god"] = "装备牌·防具<br/><b>防具技能</b>：当其他角色使用【杀】或【决斗】指定你为目标后，其需弃置一张牌，"..
  "否则此牌对你无效。",
  ["#lingling__door_god-discard"] = "门神：你需弃置一张牌，否则%arg对 %src 无效",
}

local paint_zhongkuiSkill = fk.CreateTriggerSkill{
  name = "#lingling__paint_zhongkui_skill",
  attached_equip = "lingling__paint_zhongkui",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not (data.card and not data.card:isVirtual()) and not player:isNude()
  end,
  on_cost = function (self, event, target, player, data)
    local card = player.room:askForDiscard(player, 1, 1, false, self.name, true, nil, "#lingling__paint_zhongkui-invoke", true)
    if #card > 0 then
      self.cost_data = {cards = card}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:throwCard(self.cost_data.cards, self.name, player, player)
    return true
  end,
}
Fk:addSkill(paint_zhongkuiSkill)
local paint_zhongkui = fk.CreateArmor{
  name = "&lingling__paint_zhongkui",
  suit = Card.Spade,
  number = 2,
  equip_skill = paint_zhongkuiSkill,
}
extension:addCard(paint_zhongkui)
Fk:loadTranslationTable{
  ["lingling__paint_zhongkui"] = "钟馗",
  ["paint_zhongkui"] = "钟馗",
  ["#lingling__paint_zhongkui_skill"] = "钟馗",
  [":lingling__paint_zhongkui"] = "装备牌·防具<br/><b>防具技能</b>：当你受到实体牌以外的方式造成的伤害时，你可以弃置一张牌防止之。",
  ["#lingling__paint_zhongkui-invoke"] = "钟馗：是否弃置一张牌，防止你受到的伤害？",
}

local paint_guanyinSkill = fk.CreateTriggerSkill{
  name = "#lingling__paint_guanyin_skill",
  attached_equip = "lingling__paint_guanyin",
  frequency = Skill.Compulsory,
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:isWounded() and math.random() < 0.6
  end,
  on_use = function(self, event, target, player, data)
    player.room:recover{
      who = player,
      num = 1,
      recoverBy = player,
      skillName = self.name,
    }
  end,
}
Fk:addSkill(paint_guanyinSkill)
local paint_guanyin = fk.CreateArmor{
  name = "&lingling__paint_guanyin",
  suit = Card.Spade,
  number = 2,
  equip_skill = paint_guanyinSkill,
}
extension:addCard(paint_guanyin)
Fk:loadTranslationTable{
  ["lingling__paint_guanyin"] = "观音",
  ["paint_guanyin"] = "观音",
  ["#lingling__paint_guanyin_skill"] = "观音",
  [":lingling__paint_guanyin"] = "装备牌·防具<br/><b>防具技能</b>：回合开始时，若你已受伤，你有60%几率回复1点体力。",
}

local lingling__shenjun_draw = fk.CreateTreasure{  --邪道
  name = "&lingling__shenjun_draw",
}
lingling__shenjun_draw.package = extension
Fk:addCard(lingling__shenjun_draw)
Fk:loadTranslationTable{
  ["lingling__shenjun_draw"] = "摸牌",
}
